/**
 * 详情对话框
 */
var HomePageInfoDlg = {
    data: {
        id: "",
        linkUrl: "",
        imageUrl: "",
        type: "",
        status: "",
        createTime: "",
        createUser: "",
        updateUser: "",
        updateTime: "",
        deleteFlag: ""
    }
};

layui.use(['form', 'admin', 'ax', 'laydate', 'upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;


    let objData = {"moduleCode": "TEMPLATE", "moduleName": "轮播图"};
    Changein.initUploadImage('#imageUrl', '#imageUrlPreview', "#imageUrlInputId", objData);

    //获取详情信息，填充表单
    var ajax = new $ax(Changein.ctxPath + "/homePage/detail?id=" + Changein.getUrlParam("id"));
    var result = ajax.start();
    var data = result.data;
    if (data.imageUrl) {
        $("#imageUrlPreview").attr("src", data.imageUrl);
        $("#imageUrlPreview").show()
    }
    form.val('homePageForm', data);

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Changein.ctxPath + "/homePage/editItem", function (data) {
            Changein.success("更新成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Changein.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    let HomePage = {};
    //加载状态
    HomePage.loadAllStatusInfo = function () {
        $.ajax({
            url: Changein.ctxPath + "/homePage/loadAllStatusInfo",
            type: "GET",
            dataType: "json",
            success: function (result) {
                if (result && result.code == 200) {
                    let list = result.data;
                    for (let type in list) {
                        let strContent = "";
                        let objList = list[type];
                        for (let i in objList) {
                            let valContent = objList[i];
                            strContent += "<option value='" + i + "'>" + valContent + "</option>";
                        }
                        let appendObj = $("select[name=\'" + type + "\']");
                        appendObj.append(strContent);
                    }
                    form.render('select');
                    form.val('homePageForm', data);
                }
            }
        });
    };
    HomePage.loadAllStatusInfo();

});